package com.cango.student.classloader.secend;

/**
 * @program: student
 * @description:
 * @author: xie jiefeng
 * @create: 2019-05-15 11:42
 */
public class boot {
    // 初始化，加载类
    public static void init() {
        Class<?>[] classList = {ClassHelper.class};
        for (Class<?> cls : classList) {
            loadClass(cls.getName(), true);
        }
    }

    public static Class<?> loadClass(String className, boolean isInitialized) {
        Class<?> cls = null;
        try {
            //进行类加载
            cls = Class.forName(className, isInitialized, getClassLoader());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return cls;
    }

    /**
     * 获取类加载器
     * 获取加载器类的实现比较简单，只需获取当前线程的ClassLoader
     */
    public static ClassLoader getClassLoader() {
        return Thread.currentThread().getContextClassLoader();
    }

    public static void main(String[] args) {
        init();
    }
}
